package ModelLayer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * A sale object.
 * 31/05/2012
 * @author cbjerg
 * @version 0.1
 */

public class Sale {
	
	private int saleId;
	private double total;
	private String date;
	private ArrayList<PartSale> partSales;
	private Event event;
	private Employee employee;
	
	/**
	 * An empty sale object.
	 */
	
	public Sale()
	{
		
	}
	
	/**
	 * A sale object that calculates the date itself and initialize an ArrayList
	 * @param event The current event if there is any.
	 * @param Employee The employee who handles the sale.
	 */
	
	public Sale(Event event, Employee employee)
	{
		saleId=0;
		date = getDateTime();
		this.event = event;
		partSales = new ArrayList<PartSale>();
		this.employee = employee;
	}

	/**
	 * @return the saleId
	 */
	public int getSaleId() {
		return saleId;
	}

	/**
	 * @param saleId the saleId to set
	 */
	public void setSaleId(int saleId) {
		this.saleId = saleId;
	}

	/**
	 * @return the total
	 */
	public double getTotal() {
		return total;
	}

	/**
	 * @param total the total to set
	 */
	public void setTotal(double total) {
		this.total = total;
	}

	/**
	 * @return the date
	 */
	public String getDate() {
		return date;
	}

	/**
	 * @param date the date to set
	 */
	public void setDate(String date) {
		this.date = date;
	}


	/**
	 * @return the partsale
	 */
	public ArrayList<PartSale> getPartsales() {
		return partSales;
	}

	/**
	 * @param partsale the partsale to add
	 */
	public void addPartSale(PartSale partSale) {
		partSales.add(partSale);
	}

	/**
	 * @return the event
	 */
	public Event getEvent() {
		return event;
	}

	/**
	 * @param event the event to set
	 */
	public void setEvent(Event event) {
		this.event = event;
	}
	
	
	/**
	 * @return the employee
	 */
	public Employee getEmployee() {
		return employee;
	}

	/**
	 * @param employee the employee to set
	 */
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	/**
	 * 
	 * @return the date
	 */
	
	private String getDateTime() 
    {
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = new Date();
        return dateFormat.format(date);
    }
	
	/**
	 * Calculates the total price of the sale.
	 */
	
	public void calculateTotalPrice()
	{
		total = 0;
		for(PartSale partSale : partSales)
		{
			total = total + partSale.getPrice();
		}
		
	}
	
	

	
}
